#include <windows.h>
#include <QtGui>
#include <qt_windows.h>
#include <QRgb>
#include <QImage>
#include "NativeCapture.h"
#include <QApplication>
#include <QDesktopWidget>

NativeCapture::NativeCapture()
{
}

void NativeCapture::Capture(){
		myTimer.start();

}

void NativeCapture::Release(){
		WorkTime = myTimer.elapsed();
}

int NativeCapture::GetTime(){
		return WorkTime;
}

void NativeCapture::MakeScreenshot(int x1, int y1, int x2, int y2){
		m_map = QPixmap::grabWindow(QApplication::desktop()->winId(),x1,y1,x2,y2);
}

void NativeCapture::SaveToFile(char* filename){
		m_map.save(filename);
}

QColor NativeCapture::GetAverage(){
		QRgb rgb = m_map.scaled(1,1,Qt::IgnoreAspectRatio,Qt::SmoothTransformation).toImage().pixel(0,0);
		return QColor(rgb);
}
